<template>
  <!-- 批量确认加班工时 -->
  <Dialog
    ref="sailings"
    dialogCls="mydlgg"
    headerCls="mydlgg-head"
    footerCls="mydlgg-foot"
    :dialogStyle="{ width: '450px' }"
    :modal="true"
    borderType="thin"
  >
    <div slot="header">
      <span class="headerIcon newlyAdded"></span>
      <span class="titleStyle">批量确认加班工时</span>
    </div>

    <div class="insidePadding">
      <!-- 这个div必须保留 -->
      <fieldset class="fieldsetStyle">
        <legend>
          <b class="fieldsetLegend">确认操作</b>
        </legend>
        <!-- fieldset、legend如果需要带边框加标题的容器这俩标签必须保留 -->
        <div style="padding:10px 0 30px 0">
          <div class="flexStartDiv">
            <input
              type="radio"
              name="sex"
              value="1"
              v-model="sailingsHours.radio1"
            />
            <span>统一修改为待确认小时加班</span>
          </div>

          <div class="flexStartDiv">
            <input
              type="radio"
              name="sex"
              value="2"
              v-model="sailingsHours.radio1"
            />
            <Label>自定义工时</Label>
            <NumberBox
              :max="24"
              :min="0"
              :value="0"
              :prefix="sailingsHours.hours < 10 ? '0' : ''"
              :spinners="true"
              style="width:60px"
              v-model="sailingsHours.hours"
            ></NumberBox>
            <span class="inputStyle3">小时</span>
            <NumberBox
              :max="59"
              :min="0"
              :value="0"
              :prefix="sailingsHours.minutes < 10 ? '0' : ''"
              :spinners="true"
              style="width:60px"
              v-model="sailingsHours.minutes"
            ></NumberBox
            >分钟
          </div>
        </div>
      </fieldset>
    </div>

    <div slot="footer" style="border:none">
      <div class="footerDiv">
        <!-- footer、footerDiv这两个div必须保留 -->
        <LinkButton @click="submitSailings" class="saveBtn">保存</LinkButton>
        <LinkButton @click="closeSailings" class="cancelBtn">返回</LinkButton>
      </div>
    </div>
  </Dialog>
</template>

<script>
// 考勤卡页面js
import timeCard from "@/api/timeCard/timeCard";

export default {
  props: {
    selectedRowsdatasids: String,
    selectedRowsdatas: Array,
    parentSearch: Function
  },
  components: {},
  name: "",
  data() {
    return {
      sailingsHours: {
        radio1: "1",
        hours: 0,
        minutes: 0
      }
    };
  },
  mounted() {
    this.$refs.sailings.close();
  },
  methods: {
    // 批量确认加班工时--打开
    newAddSailings() {
      console.log(this.selectedRowsdatasids);
      console.log(this.selectedRowsdatas);
      this.$refs.sailings.open();
    },
    // 批量确认加班工时--提交
    submitSailings() {
      let allTimes = 0;

      if (this.sailingsHours.radio1 == 1) {
        // 拿到选中的行id和日期
        allTimes = 0;
      } else {
        if (this.sailingsHours.hours == 0 && this.sailingsHours.minutes == 0) {
          this.$messager.alert({
            title: "系统提示",
            icon: "info",
            msg: "自定义工时不能为0！"
          });
          return;
        } else {
          allTimes = this.sailingsHours.hours * 60 + this.sailingsHours.minutes;
          let arr2 = this.selectedRowsdatas.filter(res => {
            return allTimes > res.daiQueRen2;
          });
          if (arr2.length > 0) {
            this.$messager.alert({
              title: "系统提示",
              icon: "info",
              msg: "自定义工时大于待确认工时，请重新填写！"
            });
            return;
          }
        }
      }

      let param = {
        id: this.selectedRowsdatasids,
        type: this.sailingsHours.radio1 == 1 ? 2 : 3,
        overtimeHours: allTimes,
        startDate: "",
        endDate: ""
      };
      console.log(param);
      timeCard.savaOvertimeOrRest(param).then(res => {
        if (res.success) {
          this.$messager.alert({
            title: "系统提示",
            icon: "success",
            msg: "保存成功！"
          });
          this.closeSailings();
          // 刷新表格
          this.parentSearch();
        } else {
          this.$messager.alert({
            title: "系统提示",
            icon: "error",
            msg: res.message
          });
          this.closeSailings();
        }
      });
    },
    // 批量确认加班工时--关闭
    closeSailings() {
      this.$refs.sailings.close();
      this.sailingsHours.radio1 = "1";
      this.sailingsHours.hours = 0;
      this.sailingsHours.minutes = 0;
    }
  }
};
</script>

<style scoped></style>
